package com.gzzyy.facerecognition.http

import com.gzzyy.facerecognition.http.converter.FastJsonConverterFactory
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import java.util.concurrent.TimeUnit

object RetrofitClient {
    const val BaseUrl = "http://block.ganzhouii.com/"
    const val ImageUploadUrl = "http://test.ainankang.com"
    const val DEFAULT_TIMEOUT = 100L

    private val httpLogInterceptor = HttpLoggingInterceptor(HttpLogger())
        .also { it.level = HttpLoggingInterceptor.Level.BODY }
    private val client = OkHttpClient.Builder()
        .addInterceptor(MoreBaseUrlInterceptor())
        .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
        .writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
        .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
        .addNetworkInterceptor(httpLogInterceptor)
        .build()

    val httpApi: HttpApi by lazy {
        val retrofit = Retrofit.Builder()
            .baseUrl(BaseUrl)
            .client(client)
            .addConverterFactory(FastJsonConverterFactory.create())
            .build()
        return@lazy retrofit.create(HttpApi::class.java)
    }
}